#include <memory>
#include "TcpServer.hpp"
#include "Dict.hpp"
#include "Command.hpp"


using namespace myThreadPool;



void Usage(std::string cmd){
    std::cout << "please use : " << cmd << " server_port" << std::endl;
    exit(USAGE_ERROR); 
}

//using func_t = std::function<std::string(std::string, const InetAddr&)>;

std::string default_test(std::string message, const InetAddr& addr){
    LOG(LogLevel::DEBUG) << "short service";
    std::string ret = addr.GetFormatStr() + " # " + message;
    return ret;
}

// ./TCP_SERVER.exe port
int main(int argc, char* argv[]){
    if(argc != 2) Usage(argv[0]);

    uint16_t port = (uint16_t)std::stoi(argv[1]);


    Dict dict;
    Command command;


    //auto l1 = [&dict](std::string word, const InetAddr& addr)->std::string{return dict.Translate(word, addr);};
    /* std::unique_ptr<TcpServer> Pserver = std::make_unique<TcpServer>(port, 
        [&dict](std::string word, const InetAddr& addr)->std::string{return dict.Translate(word, addr);}); */

    //auto l2 = [&command](std::string cmd, const InetAddr& addr)->std::string{return command.Execute(cmd, addr);};
    std::unique_ptr<TcpServer> Pserver = std::make_unique<TcpServer>(port, 
        [&command](std::string cmd, const InetAddr& addr)->std::string{return command.Execute(cmd, addr);});
        
    Pserver->Init();
    Pserver->Run();

    return 0;
}